package cn.iocoder.yudao.module.xiaoBizHandler.service.tbGenGoodsRegister;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.xiaoBizHandler.controller.admin.tbGenGoodsRegister.vo.*;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.dataobject.tbGenGoodsRegister.XTbGenGoodsRegisterDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.xiaoBizHandler.convert.tbGenGoodsRegister.XTbGenGoodsRegisterConvert;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.mysql.tbGenGoodsRegister.XTbGenGoodsRegisterMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.xiaoBizHandler.enums.ErrorCodeConstants.*;

/**
 * 物品登记 Service 实现类
 *
 * @author xiaosy
 */
@Service
@Validated
public class XTbGenGoodsRegisterServiceImpl implements XTbGenGoodsRegisterService {

    @Resource
    private XTbGenGoodsRegisterMapper xTbGenGoodsRegisterMapper;

    @Override
    public String createXTbGenGoodsRegister(XTbGenGoodsRegisterCreateReqVO createReqVO) {
        // 插入
        XTbGenGoodsRegisterDO xTbGenGoodsRegister = XTbGenGoodsRegisterConvert.INSTANCE.convert(createReqVO);
        xTbGenGoodsRegisterMapper.insert(xTbGenGoodsRegister);
        // 返回
        return xTbGenGoodsRegister.getId();
    }

    @Override
    public void updateXTbGenGoodsRegister(XTbGenGoodsRegisterUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateXTbGenGoodsRegisterExists(updateReqVO.getId());
        // 更新
        XTbGenGoodsRegisterDO updateObj = XTbGenGoodsRegisterConvert.INSTANCE.convert(updateReqVO);
        xTbGenGoodsRegisterMapper.updateById(updateObj);
    }

    @Override
    public void deleteXTbGenGoodsRegister(String id) {
        // 校验存在
        this.validateXTbGenGoodsRegisterExists(id);
        // 删除
        xTbGenGoodsRegisterMapper.deleteById(id);
    }

    private void validateXTbGenGoodsRegisterExists(String id) {
        if (xTbGenGoodsRegisterMapper.selectById(id) == null) {
            throw exception(XT_B_GEN_GOODS_REGISTER_NOT_EXISTS);
        }
    }

    @Override
    public XTbGenGoodsRegisterDO getXTbGenGoodsRegister(String id) {
        return xTbGenGoodsRegisterMapper.selectById(id);
    }

    @Override
    public List<XTbGenGoodsRegisterDO> getXTbGenGoodsRegisterList(Collection<String> ids) {
        return xTbGenGoodsRegisterMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<XTbGenGoodsRegisterDO> getXTbGenGoodsRegisterPage(XTbGenGoodsRegisterPageReqVO pageReqVO) {
        return xTbGenGoodsRegisterMapper.selectPage(pageReqVO);
    }

    @Override
    public List<XTbGenGoodsRegisterDO> getXTbGenGoodsRegisterList(XTbGenGoodsRegisterExportReqVO exportReqVO) {
        return xTbGenGoodsRegisterMapper.selectList(exportReqVO);
    }

}

